import env from '../util/env'
export default class MapHelper {
  //添加速度marker
  static addSpeedMarker(){
    let el = document.createElement('div');
    env.speed_el = el;
    el.id = 'speed_marker';
    el.style["background-image"] = "url(\'./static/images/index/pop.png\')";
    el.style["background-repeat"] = "no-repeat";
    el.style.width = "60px";
    el.style.height = "32px";
    el.style["background-size"] = "contain";
    el.style.position = "absolute";
    el.style.cursor = "pointer";
    env.speedMarker =new minemap.Marker(el, {offset: [-60, -40]});
    return el;
  }
  //添加预警marker
  static addNormalMarker(type){
    let el = document.createElement('div');
    el.id = 'close_marker';
    if(type === "warn"){
      el.style["background-image"] = "url(\'./static/images/history/warn-icon.png\')";
    }else if(type === "start"){
      el.style["background-image"] = "url(\'./static/images/history/start-icon.png\')";
    }else{
      el.style["background-image"] = "url(\'./static/images/history/end-icon.png\')";
    }
    el.style["background-repeat"] = "no-repeat";
    if (document.body.clientWidth > 3800) {
      el.style.width = "50px";
      el.style.height = "50px";
      el.style["background-size"] = "50px 50px";
    } else {
      el.style.width = "35px";
      el.style.height = "35px";
      el.style["background-size"] = "contain";
    }
    el.style.position = "absolute";
    el.style.cursor = "pointer";
    return el;
  }

  //添加预警弹框
  static addWarnPopup(point,carid,time){
    let warnText = null;
    switch (point.warnflag) {
      case 'pressingup':
        warnText = "急加速";
        break;
      case 'pressingdown':
        warnText = "急减速";
        break;
      case 'pressingturn':
        warnText = "急转弯";
        break;
      case 'tireddrive':
        warnText = "疲劳驾驶";
        break;
      case 'notflameout':
        warnText = "停车未熄火超时";
        break;
      case 'parked':
        warnText = "停车统计";
        break;
      case 'speed':
        warnText = "超速";
        break;
      case 'weight':
        warnText = "超重";
        break;
      default:
        warnText = "违规";
        break;
    }
    let div = document.createElement('div')
    div.className = 'warn-popup'

    let img = document.createElement('img')
    img.className = 'warn-img'
    img.src =  './static/images/history/warn-large.png'
    div.appendChild(img)

    let p1 = document.createElement('p')
    p1.innerText = "违规事件:"+warnText;
    div.appendChild(p1)

    let p2 = document.createElement('p')
    p2.innerText = "在"+point.road+"路段最高时速为"+point.speed+"km/h";
    div.appendChild(p2)

    let p3 = document.createElement('p')
    p3.innerText = "车辆ID:"+carid;
    div.appendChild(p3)

    let p4 = document.createElement('p')
    p4.innerText = "车速:"+point.speed+"km/h";
    div.appendChild(p4)

    let p5 = document.createElement('p')
    p5.innerText = "定位时间:"+time;
    div.appendChild(p5)

    let content_tip = document.createElement('span')
    content_tip.className = 'content-tip-large'
    div.appendChild(content_tip)


    return div;
  }

  //添加普通弹框
  static addNormalPopup(text){
    let div = document.createElement('div')
    div.className = 'normal-popup'
    div.style.width = 'auto'

    let p_name = document.createElement('span')
    p_name.className = 'normal-text'
    p_name.innerText = text

    let content_tip = document.createElement('span')
    content_tip.className = 'content-tip'

    div.appendChild(p_name)
    div.appendChild(content_tip)
    return div;
  }

  static createPopupDom(rootP,name,content){
    rootP.className = 'p-tip';
    let span1 = document.createElement('span')
    span1.className = 'name-tip'
    span1.innerHTML = name;
    rootP.appendChild(span1)
    let span2 = document.createElement('span')
    span1.appendChild(span2)
    let span3 = document.createElement('span')
    span3.innerHTML = content;
    rootP.appendChild(span3)
  }

  static addCarTrackPopup(carInfo){
    let div = document.createElement('div')
    div.className = 'warn-popup'

    let p1 = document.createElement('p')
    p1.className = 'p-tip';
    let span1 = document.createElement('span')
    span1.className = 'name-tip'
    span1.innerText = "车牌号: ";
    p1.appendChild(span1)
    let span2 = document.createElement('span')
    span1.appendChild(span2)
    let span3 = document.createElement('span')
    span3.innerText = carInfo.id;
    p1.appendChild(span3)
    div.appendChild(p1)

    let p2 = document.createElement('p')
    this.createPopupDom(p2,'车辆类型: ',carInfo.carName);
    div.appendChild(p2)


    let p3 = document.createElement('p')
    this.createPopupDom(p3,'所属公司: ',carInfo.company);
    div.appendChild(p3)

    let p4 = document.createElement('p')
    let telInfo = carInfo.driver?carInfo.driver :'暂无数据';
    this.createPopupDom(p4,'司机姓名: ',telInfo);
    div.appendChild(p4)
    let p6 = document.createElement('p')
    let telStr = carInfo.tel?carInfo.tel :'暂无数据';
    this.createPopupDom(p6,'联系方式: ',telStr);
    div.appendChild(p6)
    let p5 = document.createElement('p')
    p5.className = 'p-btn';
    let btn = document.createElement('span')
    btn.className = 'track-btn'
    btn.id = carInfo.id
    btn.innerText = "跟踪";
    p5.appendChild(btn);
    div.appendChild(p5);

    let content_tip = document.createElement('span')
    content_tip.className = 'content-tip-large'
    div.appendChild(content_tip)


    return div;
  }

  //城市一张图弹框
  static addCityMapPopup(point){
    let warnText = null;
    let div = document.createElement('div')
    div.className = 'warn-popup';

    let p1 = document.createElement('p')
    p1.className = 'p-tip';
    let span1 = document.createElement('span')
    span1.className = 'title-tip'
    span1.innerHTML = point.name;;
    p1.appendChild(span1)
    div.appendChild(p1)

    let p2 = document.createElement('p')
    if(point.address == ""){
      point.address = "暂无";
    }
    this.createPopupDom(p2,'地址:',point.address);
    div.appendChild(p2)

    let p3 = document.createElement('p')
    if(point.manager ==""){
      point.manager = "暂无";
    }
    this.createPopupDom(p3,'负责人:',point.manager);
    div.appendChild(p3)

    let p4 = document.createElement('p')
    if(point.tel == ""){
      point.tel = "暂无";
    }
    this.createPopupDom(p4,'联系方式:',point.tel);
    div.appendChild(p4)


    let p5 = document.createElement('p')
    p5.className = 'p-tip';
    let spanTitle5 = document.createElement('span')
    spanTitle5.className = 'name-tip'
    spanTitle5.innerText = "企业简介";
    let icon = document.createElement('i')
    icon.className = 'icon'


    let spanValue5 = document.createElement('span');
    if(point.des == ""){
      point.des = "暂无";
      spanValue5.style.height = '20px';
    }else{
      spanValue5.style.height = '80px';
      spanValue5.style.overflow = "scroll";
    }
    spanValue5.className = 'infor-span';
    spanValue5.innerHTML = point.des;
    spanValue5.style.display = 'none';

    p5.appendChild(spanTitle5)
    p5.appendChild(icon)
    p5.appendChild(spanValue5)
    div.appendChild(p5)

    let flag = false;  //不可见
    icon.onclick = function () {
      if(flag){
        spanValue5.style.display = 'none';
        flag = false
      }else{
        spanValue5.style.display = 'block';
        flag = true
      }
    }

    let content_tip = document.createElement('span')
    content_tip.className = 'content-tip-large'
    div.appendChild(content_tip)
    return div;
  }

}
